package com.mallcai.bigdata.ladon.tools.dingtalk;

import com.alibaba.fastjson.JSON;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * described :
 * Created by CaKeDou on 2019-08-20 15:05.
 * Modify:
 */
@Data
@EqualsAndHashCode
@RequiredArgsConstructor
public class Message {
    private final String text;
    private List<String> atMobiles = new ArrayList();

    public String toJsonString() {
        HashMap items = new HashMap();
        items.put("msgtype", "text");
        HashMap textContent = new HashMap();
        if (StringUtils.isBlank(this.text)) {
            throw new IllegalArgumentException("text should not be blank");
        } else {
            textContent.put("content", this.text);
            items.put("text", textContent);
            HashMap atItems = new HashMap();
            if (this.atMobiles != null && !this.atMobiles.isEmpty()) {
                atItems.put("atMobiles", this.atMobiles);
            } else {
                atItems.put("isAtAll", Boolean.valueOf(true));
            }

            items.put("at", atItems);
            return JSON.toJSONString(items);
        }
    }
}
